﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _4_3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void radioButton_CheckedChanged(object sender, EventArgs e)
        {
            CalculateResult(); // 调用计算方法
        }

        private void checkBox_CheckedChanged(object sender, EventArgs e)
        {
            // 设置字体格式
            FontStyle style = FontStyle.Regular;
            if (cb_Bold.Checked) style |= FontStyle.Bold;
            if (cb_Italic.Checked) style |= FontStyle.Italic;
            txt_Result.Font = new Font(txt_Result.Font.Name, txt_Result.Font.Size, style);
            // 设置字体颜色
            txt_Result.ForeColor = cb_Red.Checked ? Color.Red : Color.Black;
        }

        // 计算结果的通用方法
        private void CalculateResult()
        {
            try
            {
                double x = double.Parse(txt_Param.Text);
                double y = 0;
                if (rb_Sin.Checked) y = Math.Sin(x);
                else if (rb_Cos.Checked) y = Math.Cos(x);
                else if (rb_Tan.Checked) y = Math.Tan(x);
                // 保留2位小数
                txt_Result.Text = Math.Round(y, 2).ToString();
            }
            catch
            {
                MessageBox.Show("参数必须是数字！", "错误提示");
                txt_Param.Text = "";
            }
        }

        private void txt_Param_Leave(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(txt_Param.Text)) // 非空时才触发
            {
                CalculateResult(); // 自动计算并输出结果
            }
        }
    }
}
